---
title: "MySQL Log"
date: 2019-9-4
categories:
- mysql
tags:
---

<div id="content">
<p>
MySQL有三个参数用于设置general log：
</p>
<ul class="org-ul">
<li>general_log：开启(ON) 关闭(OFF)。</li>
<li>log_output：日志输出的模式。FILE表示输出到文件，TABLE表示输出到mysq库的general_log表，NONE表示不记录general_log。</li>
<li>general_log_file：日记输出文件的路径，这是log_output=FILE时才会输出到此文件。</li>
</ul>
<p>
查看是否开启了general log
</p>
<div class="org-src-container">
<pre class="src src-sql">show variables <span style="font-weight: bold;">where</span> Variable_name="general_log";
</pre>
</div>
<p>
设置日志模式为TABLE，FILE
</p>
<div class="org-src-container">
<pre class="src src-sql"><span style="font-weight: bold;">set</span> <span style="font-weight: bold;">global</span> general_log=<span style="font-style: italic;">'ON'</span>;
<span style="font-weight: bold;">set</span> <span style="font-weight: bold;">global</span> log_output=<span style="font-style: italic;">'TABLE,FILE'</span>;
</pre>
</div>
<p>
查询日志表：
</p>
<div class="org-src-container">
<pre class="src src-sql"><span style="font-weight: bold;">select</span> * <span style="font-weight: bold;">from</span> mysql.general_log;
# 显示出的<span style="font-weight: bold;">sql</span>语句为<span style="font-weight: bold; text-decoration: underline;">blob</span>，通过下面的<span style="font-weight: bold;">sql</span>显示<span style="font-weight: bold; text-decoration: underline;">blob</span>
<span style="font-weight: bold;">select</span> <span style="font-weight: bold;">convert</span>(argument <span style="font-weight: bold;">using</span> utf8) <span style="font-weight: bold;">from</span> mysql.general_log;
</pre>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2019-9-4</p>
<p class="author">Author: amo</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
